1 package org.apache.maven.surefire.junitcore;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.Properties;
25
26 import org.apache.maven.surefire.booter.ProviderParameterNames;
27
28
29
30
31 public final class JUnitCoreParameters
32 {
33 public static final String PARALLEL_KEY = ProviderParameterNames.PARALLEL_PROP;
34
35 public static final String PERCORETHREADCOUNT_KEY = "perCoreThreadCount";
36
37 public static final String THREADCOUNT_KEY = ProviderParameterNames.THREADCOUNT_PROP;
38
39 public static final String THREADCOUNTSUITES_KEY = ProviderParameterNames.THREADCOUNTSUITES_PROP;
40
41 public static final String THREADCOUNTCLASSES_KEY = ProviderParameterNames.THREADCOUNTCLASSES_PROP;
42
43 public static final String THREADCOUNTMETHODS_KEY = ProviderParameterNames.THREADCOUNTMETHODS_PROP;
44
45 public static final String USEUNLIMITEDTHREADS_KEY = "useUnlimitedThreads";
46
47 public static final String PARALLEL_TIMEOUT_KEY = ProviderParameterNames.PARALLEL_TIMEOUT_PROP;
48
49 public static final String PARALLEL_TIMEOUTFORCED_KEY = ProviderParameterNames.PARALLEL_TIMEOUTFORCED_PROP;
50
51 public static final String PARALLEL_OPTIMIZE_KEY = ProviderParameterNames.PARALLEL_OPTIMIZE_PROP;
52
53 private final String parallel;
54
55 private final Boolean perCoreThreadCount;
56
57 private final int threadCount;
58
59 private final int threadCountSuites;
60
61 private final int threadCountClasses;
62
63 private final int threadCountMethods;
64
65 private final double parallelTestsTimeoutInSeconds;
66
67 private final double parallelTestsTimeoutForcedInSeconds;
68
69 private final Boolean useUnlimitedThreads;
70
71 private final boolean parallelOptimization;
72
73 public JUnitCoreParameters( Properties properties )
74 {
75 parallel = properties.getProperty( PARALLEL_KEY, "none" ).toLowerCase();
76 perCoreThreadCount = Boolean.valueOf( properties.getProperty( PERCORETHREADCOUNT_KEY, "true" ) );
77 threadCount = Integer.valueOf( properties.getProperty( THREADCOUNT_KEY, "0" ) );
78 threadCountMethods = Integer.valueOf( properties.getProperty( THREADCOUNTMETHODS_KEY, "0" ) );
79 threadCountClasses = Integer.valueOf( properties.getProperty( THREADCOUNTCLASSES_KEY, "0" ) );
80 threadCountSuites = Integer.valueOf( properties.getProperty( THREADCOUNTSUITES_KEY, "0" ) );
81 useUnlimitedThreads = Boolean.valueOf( properties.getProperty( USEUNLIMITEDTHREADS_KEY, "false" ) );
82 parallelTestsTimeoutInSeconds =
83 Math.max( Double.valueOf( properties.getProperty( PARALLEL_TIMEOUT_KEY, "0" ) ), 0 );
84 parallelTestsTimeoutForcedInSeconds =
85 Math.max( Double.valueOf( properties.getProperty( PARALLEL_TIMEOUTFORCED_KEY, "0" ) ), 0 );
86 parallelOptimization = Boolean.valueOf( properties.getProperty( PARALLEL_OPTIMIZE_KEY, "true" ) );
87 }
88
89 private static Collection<String> lowerCase( String... elements )
90 {
91 ArrayList<String> lowerCase = new ArrayList<String>();
92 for ( String element : elements )
93 {
94 lowerCase.add( element.toLowerCase() );
95 }
96 return lowerCase;
97 }
98
99 private boolean isAllParallel()
100 {
101 return "all".equals( parallel );
102 }
103
104 public boolean isParallelMethods()
105 {
106 return isAllParallel() || lowerCase( "both", "methods", "suitesAndMethods", "classesAndMethods" ).contains(
107 parallel );
108 }
109
110 public boolean isParallelClasses()
111 {
112 return isAllParallel() || lowerCase( "both", "classes", "suitesAndClasses", "classesAndMethods" ).contains(
113 parallel );
114 }
115
116 public boolean isParallelSuites()
117 {
118 return isAllParallel() || lowerCase( "suites", "suitesAndClasses", "suitesAndMethods" ).contains( parallel );
119 }
120
121
122
123
124 @Deprecated
125 public boolean isParallelBoth()
126 {
127 return isParallelMethods() && isParallelClasses();
128 }
129
130 public Boolean isPerCoreThreadCount()
131 {
132 return perCoreThreadCount;
133 }
134
135 public int getThreadCount()
136 {
137 return threadCount;
138 }
139
140 public int getThreadCountMethods()
141 {
142 return threadCountMethods;
143 }
144
145 public int getThreadCountClasses()
146 {
147 return threadCountClasses;
148 }
149
150 public int getThreadCountSuites()
151 {
152 return threadCountSuites;
153 }
154
155 public Boolean isUseUnlimitedThreads()
156 {
157 return useUnlimitedThreads;
158 }
159
160 public double getParallelTestsTimeoutInSeconds()
161 {
162 return parallelTestsTimeoutInSeconds;
163 }
164
165 public double getParallelTestsTimeoutForcedInSeconds()
166 {
167 return parallelTestsTimeoutForcedInSeconds;
168 }
169
170 public boolean isNoThreading()
171 {
172 return !isParallelismSelected();
173 }
174
175 public boolean isParallelismSelected()
176 {
177 return isParallelSuites() || isParallelClasses() || isParallelMethods();
178 }
179
180 public boolean isParallelOptimization()
181 {
182 return parallelOptimization;
183 }
184
185 @Override
186 public String toString()
187 {
188 return "parallel='" + parallel + '\'' + ", perCoreThreadCount=" + perCoreThreadCount + ", threadCount="
189 + threadCount + ", useUnlimitedThreads=" + useUnlimitedThreads + ", threadCountSuites=" + threadCountSuites
190 + ", threadCountClasses=" + threadCountClasses + ", threadCountMethods=" + threadCountMethods
191 + ", parallelOptimization=" + parallelOptimization;
192 }
193 }